﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Biblioteca.classesBasicas.jogo;
using Biblioteca.fachada;
using Biblioteca.classesBasicas.pessoa;

namespace Desktop.views.cruds.crudsJogo.crudPartida
{
    public partial class MenuPartida : Form
    {
        private TelaInicial telaInicial;
        private Partida partida = new Partida();
        private List<Partida> listaPartidas;
        private Fachada fachada = new Fachada();

        //private EquipamentosCliente equipamentos;
        
        public MenuPartida(TelaInicial telaInicial)
        {
            this.telaInicial = telaInicial;

            telaInicial.Hide();
            InitializeComponent();
        }
               
        private void buttonCadastrar_Click(object sender, EventArgs e)
        {
            PartidaReserva partidaReserva = new PartidaReserva(this);
            partidaReserva.ShowDialog();
        }

        private void buttonSair_Click(object sender, EventArgs e)
        {
            telaInicial.Show();
            this.Dispose(); ;
        }

        private void MenuPartida_FormClosed(object sender, FormClosedEventArgs e)
        {
            telaInicial.Show();
            this.Dispose(); ;
        }

        private void MenuPartida_Load(object sender, EventArgs e)
        {
            this.carregarGridViewPartida();
        }


        private void dataGridViewPartida_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                DataGridViewRow row = this.dataGridViewPartida.Rows[e.RowIndex];

                partida.Id = row.Cells[0].Value.ToString();
                partida.Tipo = row.Cells[1].Value.ToString();
                partida.Hora = row.Cells[2].Value.ToString();
                partida.Duracao = row.Cells[3].Value.ToString();
                partida.Reserva = new Reserva();
                partida.Reserva.Id = row.Cells[4].Value.ToString();
                partida.Funcionario = new Funcionario();
                partida.Funcionario.Id = row.Cells[5].Value.ToString();

                AlterarRemoverPartida alterar = new AlterarRemoverPartida(this, partida);
                alterar.ShowDialog();
            }
        }


        public void carregarGridViewPartida()
        {
            listaPartidas = fachada.listarPartida();

            dataGridViewPartida.Rows.Clear();
            dataGridViewPartida.ColumnCount = 6;
            dataGridViewPartida.ColumnHeadersVisible = true;
            dataGridViewPartida.AllowUserToAddRows = false;

            DataGridViewCellStyle columnHeaderStyle =
            new DataGridViewCellStyle();
            columnHeaderStyle.BackColor = Color.Aqua;
            columnHeaderStyle.Font =
                new Font("Verdana", 10, FontStyle.Bold);
            this.dataGridViewPartida.ColumnHeadersDefaultCellStyle =
                columnHeaderStyle;

            //dataGridViewReserva.DataSource = listaReserva;

            this.dataGridViewPartida.Columns[0].Name = "ID";
            this.dataGridViewPartida.Columns[1].Name = "TIPO";
            this.dataGridViewPartida.Columns[2].Name = "HORA";
            this.dataGridViewPartida.Columns[3].Name = "DURACAO";
            this.dataGridViewPartida.Columns[4].Name = "ID_RESERVA";
            this.dataGridViewPartida.Columns[5].Name = "ID_FUNCIONARIO";

            foreach (Partida elemento in listaPartidas)
            {
                dataGridViewPartida.Rows.Add(elemento.Id, elemento.Tipo, elemento.Hora, elemento.Duracao, elemento.Reserva.Id, elemento.Funcionario.Id);
            }   
        }

        public void cancelar()
        {
            telaInicial.Show();
            this.Dispose();
        }

    }
}
